package ks.client.gui.user.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import ks.client.UserContext;
import ks.client.ipc.Client;
import ks.client.lobby.Lobby;
import org.w3c.dom.Document;
import ks.framework.common.Message;
import ks.managers.icon.Icon;
import ks.managers.icon.IconManager;

/**
 * 
 * This controller listens for the "Update Account" button to be clicked
 * and creates and sends an account message to the server
 * 
 * @author Jennifer Hunt
 *
 */
public class UpdateAccountClickController implements ActionListener{
	
	Lobby lobby;
	UserContext context;
	JPanel panel;
	
	/**
	 * 
	 * PluginUnsuspendClick constructor.
	 * 
	 * @param lobby
	 * @param table
	 */
	public UpdateAccountClickController(Lobby lobby) {
		this.lobby = lobby;
		this.context = lobby.getUserContext();
		
	}

	/**
	 * 
	 * Constructs and sends the message on the button click.
	 * 
	 */
	public void actionPerformed(ActionEvent e){
		//An action cannot be performed on this button unless the user is logged in.
		try{
		context.getUser().isEmpty();
		}catch(NullPointerException npe){
			System.out.println("This option is only available to logged in users.");
			return;
		}
		JFrame pma = lobby.getAccountUpdateGUI();
		pma.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		pma.setTitle("Plugin Admin Controls");
		//panel.removeAll();
		panel = new JPanel();
		pma.setVisible(true);
		
IconManager im = context.getIconManager();
		// add button for each icon.
		for (Icon icon : im.getList()) {
			ImageIcon imgIcon = new ImageIcon(icon.location);
			JButton button = new JButton(icon.name);
			button.setIcon(imgIcon);
			panel.add(button);
		}
		
	}
}
